//
//  WQHomeWeatherHeaderView.m
//  WisdomQuestor
//
//  Created by 纪景城 on 2024/12/17.
//

#import "WQHomeWeatherHeaderView.h"

@implementation WQHomeWeatherHeaderView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self addSubviews:[NSArray arrayWithObjects:self.roomTitleLabel, self.moreButton, self.allDeviceImageView, self.weatherBackImageView, self.allDidImageView, self.allDidLabel, self.roomDidImageView, self.roomDidLabel, nil]];
        [self.weatherBackImageView addSubviews:[NSArray arrayWithObjects:self.weatherTypeImageVIew, self.weatherNumberLabel, self.weatherDescLabel, nil]];
        [self fragmentUI_ViewSet];
    }
    return self;
}

#pragma mark ------- Lazy Methods -------

- (void)fragmentUI_ViewSet {
    [self.roomTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kFragmemtFloat(15));
        make.top.equalTo(self.mas_top).offset(kFragmemtFloat(10));
        make.right.equalTo(self.mas_right).offset(-kFragmemtFloat(60));
    }];
    [self.moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.roomTitleLabel);
        make.right.equalTo(self.mas_right).offset(-kFragmemtFloat(11));
        make.size.mas_equalTo(kSizzleKapadate(33, 33));
    }];
    [self.allDeviceImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kFragmemtFloat(11));
        make.right.equalTo(self.mas_right).offset(-kFragmemtFloat(11));
        make.top.equalTo(self.roomTitleLabel.mas_bottom).offset(kFragmemtFloat(15));
        make.height.mas_equalTo(kFragmemtFloat(120));
    }];
    [self.weatherBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kFragmemtFloat(11));
        make.top.equalTo(self.allDeviceImageView.mas_bottom).offset(kFragmemtFloat(16));
        make.right.equalTo(self.mas_centerX).offset(-kFragmemtFloat(6));
        make.height.mas_equalTo(kFragmemtFloat(150));
    }];
    [self.weatherTypeImageVIew mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.weatherBackImageView.mas_left).offset(kFragmemtFloat(15));
        make.top.equalTo(self.weatherBackImageView.mas_top).offset(kFragmemtFloat(14));
        make.size.mas_equalTo(kSizzleKapadate(40, 34));
    }];
    [self.weatherNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.weatherBackImageView.mas_right).offset(-kFragmemtFloat(13));
        make.top.equalTo(self.weatherTypeImageVIew.mas_bottom);
    }];
    [self.weatherDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.weatherBackImageView);
        make.bottom.equalTo(self.weatherBackImageView.mas_bottom).offset(-kFragmemtFloat(20));
    }];
    [self.allDidImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-kFragmemtFloat(11));
        make.top.equalTo(self.weatherBackImageView);
        make.left.equalTo(self.mas_centerX).offset(kFragmemtFloat(6));
        make.height.mas_equalTo(kFragmemtFloat(65));
    }];
    [self.allDidLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.allDidImageView);
    }];
    [self.roomDidImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.allDidImageView);
        make.bottom.equalTo(self.weatherBackImageView);
        make.height.equalTo(self.allDidImageView);
    }];
    [self.roomDidLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.roomDidImageView);
    }];
}

- (UILabel *)roomTitleLabel {
    if (!_roomTitleLabel) {
        _roomTitleLabel = [UILabel initWithTextColor:UIColor.whiteColor weight:UIFontWeightMedium size:22];
        _roomTitleLabel.text = @"请先登陆";
    }
    return _roomTitleLabel;
}

- (UIButton *)moreButton {
    if (!_moreButton) {
        _moreButton = [UIButton initWithImage:kImageName(@"base_sanMore_icon") selectedImage:nil];
    }
    return _moreButton;
}

- (UIImageView *)allDeviceImageView {
    if (!_allDeviceImageView) {
        _allDeviceImageView = [[UIImageView alloc] initWithImage:kImageName(@"home_allDervice_image")];
    }
    return _allDeviceImageView;
}

- (UIImageView *)weatherBackImageView {
    if (!_weatherBackImageView) {
        _weatherBackImageView = [[UIImageView alloc] initWithImage:kImageName(@"home_weather_bg")];
    }
    return _weatherBackImageView;
}
- (UIImageView *)weatherTypeImageVIew {
    if (!_weatherTypeImageVIew) {
        _weatherTypeImageVIew = [[UIImageView alloc] initWithImage:kImageName(@"home_weatherType_duoyun")];
    }
    return _weatherTypeImageVIew;
}
- (UILabel *)weatherNumberLabel {
    if (!_weatherNumberLabel) {
        _weatherNumberLabel = [UILabel initWithTextColor:UIColor.whiteColor weight:UIFontWeightMedium size:13];
        NSString *weaString = @"16°C";
        NSMutableAttributedString *rightAS = [[NSMutableAttributedString alloc] initWithString:weaString];
        [rightAS addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:kFragmemtFloat(28) weight:UIFontWeightMedium]} range:NSMakeRange(0, weaString.length - 2)];
        _weatherNumberLabel.attributedText = rightAS;
    }
    return _weatherNumberLabel;
}
- (UILabel *)weatherDescLabel {
    if (!_weatherDescLabel) {
        _weatherDescLabel = [UILabel initWithTextColor:UIColor.whiteColor weight:UIFontWeightMedium size:10];
        _weatherDescLabel.numberOfLines = 0;
        NSString *weaString = @"优\n室外PM2.5";
        NSMutableAttributedString *rightAS = [[NSMutableAttributedString alloc] initWithString:weaString];
        [rightAS addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:kFragmemtFloat(13) weight:UIFontWeightMedium]} range:NSMakeRange(0, 1)];
        
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = 5;  // 设置行间距为 10 个单位
        [rightAS addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, rightAS.length)];
        
        _weatherDescLabel.attributedText = rightAS;
    }
    return _weatherDescLabel;
}

- (UIImageView *)allDidImageView {
    if (!_allDidImageView) {
        _allDidImageView = [[UIImageView alloc] initWithImage:kImageName(@"home_allDiddevice_bg")];
    }
    return _allDidImageView;
}
- (UILabel *)allDidLabel {
    if (!_allDidLabel) {
        _allDidLabel = [UILabel initWithTextColor:k_Color_222222 weight:UIFontWeightMedium size:15];
        _allDidLabel.text = @"所有设备";
    }
    return _allDidLabel;
}

- (UIImageView *)roomDidImageView {
    if (!_roomDidImageView) {
        _roomDidImageView = [[UIImageView alloc] initWithImage:kImageName(@"home_didRoom_bg")];
    }
    return _roomDidImageView;
}
- (UILabel *)roomDidLabel {
    if (!_roomDidLabel) {
        _roomDidLabel = [UILabel initWithTextColor:k_Color_222222 weight:UIFontWeightMedium size:15];
        _roomDidLabel.text = @"房间列表";
    }
    return _roomDidLabel;
}

@end
